package com.dhq.services;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;

/**
 * @author denghuanqing
 *	query index
 */
public class SearchIndex {
	public static void main(String[] args) throws SolrServerException {
		SolrServer solr = new HttpSolrServer("http://localhost:8080/solr");
		SolrQuery query = new SolrQuery();
		query.set("q","焕");
		query.setStart(0);
		query.setRows(1);
		QueryResponse response = solr.query(query);
		SolrDocumentList docs = response.getResults();
		
		// 请求查询
		response = solr.query(query);

		// 查询结果
		docs = response.getResults();
		
		//http://localhost:8080/solr/select?q=重庆市民族宗教事务委员会“十二五”重点文化建设项目&facet=on&facet.field=name
		
		for (SolrDocument doc : docs) {
			System.out.println(doc.getFieldValue("id")+" *** "+doc.getFieldValue("name"));
		}
	}
}
